<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<c:if test="${userID==null}">
  <c:redirect url="index.jsp" />
</c:if>

<c:if test="${userType!='A'}">
  <c:redirect url="main.jsp" />
</c:if>

<c:if test="${pageContext.request.method=='POST'}">
  <sql:query var="forums" dataSource="${dataSource}">
  select c_code from t_forums where c_code = ? 
  <sql:param value="${param.code}" />
  </sql:query>

  <c:choose>
    <c:when test="${forums.rowCount>0}">
      <h3>Already a forum with that code</h3>
    </c:when>

    <c:otherwise>
      <sql:update dataSource="${dataSource}">
      insert into t_forums(c_code,c_name,c_sequence) values(?,?,?) 
      <sql:param value="${param.code}" />

      <sql:param value="${param.name}" />

      <sql:param value="${param.seq}" />
      </sql:update>

      <c:redirect url="admin.jsp" />
    </c:otherwise>
  </c:choose>
</c:if>

<html>
  <head>
    <title><fmt:message key="newforum.title" bundle="${lang}"/></title>
  </head>

  <body>
    <table border="1">
      <form method="post">
        <tr>
          <td colspan="2" bgcolor="#0000FF">
            <p align="center">
              <b>
                <font size="4" color="#FFFFFF">
                <fmt:message key="newforum.title" bundle="${lang}"/>
                </font>
              </b>
            </p>
          </td>
        </tr>

        <tr>
          <td><fmt:message key="editforum.code" bundle="${lang}"/></td>

          <td>
            <input type="text" name="code" width="4" length="4"
            maxlength="4" size="20" />
          </td>
        </tr>

        <tr>
          <td><fmt:message key="editforum.name" bundle="${lang}"/></td>

          <td>
          <input type="text" name="name" value="<c:out value="${param.name}"/>"/>
          </td>
        </tr>

        <tr>
          <td><fmt:message key="editforum.number" bundle="${lang}"/></td>

          <td>
            <input type="text" name="seq" width="10" value="0"
            size="20" />
          </td>
        </tr>

        <tr>
          <td colspan="2">
            <center>
              <input type="submit" name="add" value="<fmt:message key="button.add" bundle="${lang}"/>" />
            </center>
          </td>
        </tr>
      </form>
    </table>
  </body>
</html>

